#! /usr/bin/env python
# encoding: utf-8

def configure(ctx):
	pass

def build(ctx):
	import os
	from waflib import Utils, Task

	def chmod_fun(task):
		for x in task.outputs:
			os.chmod(x.abspath(), Utils.O755)

	def remove_fun(task):
		for x in task.outputs:
			try:
				os.remove(x.abspath())
			except OSError:
				if os.path.exists(x.abspath()):
					raise ValueError('Cannot remove %r' % x)

	class complex_copy(Task.Task):
		run_str = (remove_fun, "${CP} ${SRC} ${TGT}", chmod_fun)

	ctx.env.CP = '/bin/cp'
	tsk = complex_copy(env=ctx.env.derive())
	tsk.set_inputs(ctx.path.find_resource('wscript'))
	tsk.set_outputs(ctx.path.find_or_declare('wscript.out'))
	ctx.add_to_group(tsk)


